import React, { useEffect } from 'react'
import { useLocation, } from 'react-router-dom'
import { useNavigate } from 'react-router-dom'

function Hoc_login(children) {
    function Com() {
    const navtion=useNavigate()
        let token = localStorage.getItem('token')
        let loction = useLocation()
        let list = ['/login']
        let flag = list.includes(loction.pathname)
        useEffect(() => {
            if (!token && !flag) {
                navtion('/login')
            }
        },[loction,token])
        return children
    }
    return <Com></Com>
}

export default Hoc_login
